clc;
close all;
clear all;
[slot sender receiver sendcount receivecount pdr isdata] = textread ('pdrovernumberofpackets.txt','%d%s%s%d%d%f%d');
%[slot1 sender1 receiver1 sendcount1 receivecount1 pdr1 isdata1] = textread ('pdrovernumberofpackets01.txt','%d%s%s%d%d%f%d');
OVERALL_DEVIATION = [];
[m,n]=size(slot);
current_slot = 1;
deviations = [];
count = 0;
for i=1:1:m
    if current_slot ~= slot(i)  % compute mean devation
        OVERALL_DEVIATION = [OVERALL_DEVIATION sum(deviations)/count ];
        deviations = [];
        count = 0; 
        current_slot = slot(i);
    end
    count = count + 1;
    deviations = [deviations abs(pdr(i) - 0.9)];   
end
figure;
plot(OVERALL_DEVIATION*100,'linewidth',2);
xlim([0 250]);
%set(gca, 'YTickLabel', sprintf('%d%%|', 0:10:40))
xlabel('Number of control steps','fontsize',20);
ylabel('PDR deviation(%)','fontsize',20)
set(gca,'fontsize',20);
